<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div id="app">
      <h2>refs</h2>
      <child ref="child"></child>
    </div>

    <script src="./lib/vue3.js"></script>
    <script>
      // ref如果加在组件上面，让父组件直接得到子组件实例
      const Child = {
        data() {
          return {
            a: 111,
          };
        },
        template: `
          <div>这是child子组件</div>
        `,
        mounted() {
          console.log(this);
        },
      };

      Vue.createApp({
        data() {
          return {};
        },
        components: {
          Child,
        },
        mounted() {
          console.log(this.$refs.child.a);
        },
      }).mount("#app");
    </script>
  </body>
</html>
